SlidingWindowRateLimiter

JS/TS-friendly facade over com.sorinirmies.arrow.resiliencekit.SlidingWindowRateLimiter.

import { SlidingWindowRateLimiter } from "arrow-resilience-kit";

const sw = await SlidingWindowRateLimiter.create({ maxRequests: 100, windowDurationMillis: 60_000 });
const result = await sw.execute(() => api.request());

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard

Current number of requests counted within the window.

Link copied to clipboard
fun <T> execute(block: () -> Promise<T>): Promise<T>

Executes block if within the window's limit; rejects otherwise.

Link copied to clipboard

Resets the window and clears statistics.

Link copied to clipboard

Current statistics snapshot.

Link copied to clipboard

Tries to acquire a slot without executing anything. Resolves true if acquired.

Link copied to clipboard
fun <T> tryExecute(block: () -> Promise<T>): Promise<T?>

Executes block only if a slot is immediately available, resolving null otherwise.